package cn.knightzz.service.impl;

import cn.knightzz.entity.SysRole;
import cn.knightzz.entity.SysUser;
import cn.knightzz.entity.SysUserRole;
import cn.knightzz.mapper.SysUserRoleMapper;
import cn.knightzz.service.SysRoleService;
import cn.knightzz.service.SysUserRoleService;
import cn.knightzz.service.SysUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 系统管理 - 用户角色关联表  服务实现类
 * </p>
 *
 * @author knightzz
 * @since 2021-04-09
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements SysUserRoleService {

    @Resource
    SysUserService userService;

    @Resource
    SysRoleService roleService;

    @Override
    public List<String> getRoleCodeByUserName(String username) {

        // 存储RoleCode
        List<String> roleCodeList = new ArrayList<>();
        // 根据用户名获取用户信息
        SysUser user = userService.getUserByUserName(username);
        // 根据用户id查询角色信息
        // 当前项目一个用户对应一个角色
        Long roleId = user.getType();
        // 根据角色id获取角色信息
        SysRole role = roleService.getRoleById(roleId.intValue());
        roleCodeList.add(role.getRoleCode());
        return roleCodeList;
    }
}
